package progress.exa37.complier;

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;

public class CompilerStudy {

    public static void main(String[] args) throws FileNotFoundException {
        // 获取java编译器对象
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        //定义输出流
        OutputStream outputStream = new FileOutputStream("output.txt");
        // 定义错误信息输出流
        OutputStream errStream = new FileOutputStream("error.txt");
        //注意这里的路径就是源文件的路径
        int result = compiler.run(null,outputStream,errStream,"../study/Java基础学习/src/main/java/Progress/exa37/complier/Test.java");
        if(result == 0){
            System.out.println("编译成功！！！");
        }
    }

}
